<template>
	<view>
		<view class="info_box">
			<view class="info_title">姓名</view>
			<view class="info_context">***</view>
		</view>
		<view class="info_box">
			<view class="info_title">年龄</view>
			<view class="info_context">{{user.age}}</view>
		</view>
		<view class="info_box">
			<view class="info_title">舌象<text class="info_context" @click="show_shexiang">（点击查看）</text></view>
		</view>
		<view class="info_box">
			<view class="info_title">其他医学类诊断资料<text class="info_context" @click="show_other_picture">（点击查看）</text></view>
		</view>
		<view class="info_box" v-for="(zd_item,index) in user.zhenduan">
			<view style="display: flex;justify-content:space-between">
				<text class="info_title">诊断{{index+1}}</text>
				<u-icon
					size="40"
					color="#FF8585"
					margin-right="50"
					name="minus-circle-fill"
					@click="del_zhenduan(index)"
				></u-icon>
			</view>
			<u-collapse-item :title="zd_item.name">
				<u-input
					class="yaofangbox"
					type="textarea"
					placeholder="请输入药方名称"
					clearable
					v-model="zd_item.yaofang.text1"
				></u-input>
			</u-collapse-item>
		</view>
		<view class="btn_list">
			<view @click="doc1_save">保存</view>
			<view>返回</view>
		</view>
	</view>
</template>

<script>
	import { get_zhenduan_info,doc1_save } from '@/util/api/api.js';
	
	export default {
		data() {
			return {
				url: "/index.php/html5/zhenduan/get_zhenduan_info",
				doc1_save_url: "/index.php/html5/zhenduan/doc2_save",
				user:{
					age:32,
					tongue:'',
					other_picture:[],
					zhenduan:[

					]
				}
			}
		},
		onLoad(e) {
			this.get_zhenduan_info(e.id)
		},
		methods: {
			async get_zhenduan_info(id){
				let that = this
				
				let res = await get_zhenduan_info({id})
				
				console.log(res)
				
				if (res.data.code==200) {
					let info = res.data.data
					
					that.id = info.id
					that.user.age = info.user.age
					that.tongue = info.tongue
					that.other_picture = info.other_picture
					let text = {}
					console.log([JSON.parse(info.text1),JSON.parse(info.text2)])
					if(info.text2){
						text = JSON.parse(info.text2)
						that.user.zhenduan = text.classesList
						console.log(that.user.zhenduan)
					}
				} else{
					that.showToast(res.message)
				}
			},
			show_shexiang(){
				uni.previewImage({
					urls:[this.user.tongue]
				})
			},
			show_other_picture(){
				uni.previewImage({
					urls:[this.user.tongue]
				})
			},
			del_zhenduan(index){
				this.user.zhenduan.splice(index,1)
				
				console.log(this.user.zhenduan)
			},
			async doc1_save(){
				let that = this
				let data = {
					id:that.id,	
					text:JSON.stringify({
						classesList:[
							that.user.zhenduan
						]
					})
				}
				
				let res = await doc2_save(data)
				
				console.log(res)
				if (res.data.code==200) {
					uni.redirectTo({
						url:'/pages/doc/ht/huanzheliebiao'
					})
				} else{
					that.showToast(res.message)
				}
			},
			showToast(text) {
				this.$refs.uToast.show({
					title: text,
					// url: '/pages/user/index'
				})
			},
		}
	}
</script>

<style lang="scss">
page{
	padding: 25rpx;
}
.info_box{
	border-bottom: 2rpx solid #F5F5F5;
	.info_title{
		font-size: 30rpx;
		font-weight: bold;
		color: #666666;
		line-height: 77rpx;
	}

	.info_context{
		font-size: 30rpx;
		font-weight: bold;
		color: #666666;
		line-height: 77rpx;
	}
}

.btn_list{
	width: 700rpx;
	margin-top: 140rpx;
	display: flex;
	
	view{
		width: 300rpx;
		height: 88rpx;
		text-align: center;
		line-height: 88rpx;
		font-size: 30rpx;
		margin: 25rpx;
		background: #15BBA2;
		border-radius: 44px;
		color: #FFFFFF;
	}
}
</style>